<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">
        
    </ui:define>

    <ui:define name="left">
       
    </ui:define>

    <ui:define name="right">
       
    </ui:define>

    <ui:define name="content">
        <h:form id="salesOrderConfirmForm">

            <p:messages showDetail="true" />
            <p:growl id="growl" sticky="true"/>
            <p:panel id="panel1" header="Sales Order">
                <h:panelGrid id="panelgrid1" columns="6" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Client ID: "/>
                    <h:outputLabel style="font-weight: bold" value="#{soManagerBean.salesOrder.customer.clientId}"/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="SalesOrder Id: "/>
                    <h:outputText id="salesOrderIdStr" value="#{soManagerBean.salesOrder.salesOrderIdStr}"/>

                    <h:outputLabel style="font-weight: bold" value="Company Name: "/>
                    <h:outputText id="companyName" value="#{soManagerBean.salesOrder.customer.companyName}" />
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="PO Number: "/>
                    <h:outputText id="poNumber" value="#{soManagerBean.salesOrder.purchaseOrder.poNumber}"/>

                    <h:outputLabel style="font-weight: bold" value="Currency: "/>
                    <h:selectOneRadio id="currency" required="true" requiredMessage="Please select one currency" value="#{soManagerBean.currency}">
                        <f:selectItem itemLabel="SGD" itemValue="SGD"/>
                        <f:selectItem itemLabel="USD" itemValue="USD"/>
                    </h:selectOneRadio>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Sales Order Date: "/>
                    <h:outputText id="poDate" value="#{soManagerBean.salesOrder.dateStr}"/>

                    <h:outputLabel style="font-weight: bold" value="Payment Mode: "/>
                    <h:selectOneRadio id="paymentMode" required="true" requiredMessage="Please select one payment mode" value="#{soManagerBean.paymentMode}">
                        <f:selectItem itemLabel="Cash-In-Advance" itemValue="CIA"/>
                        <f:selectItem itemLabel="Pay-By-Credit" itemValue="PBC"/>
                    </h:selectOneRadio>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>                   
                    <h:outputLabel style="font-weight: bold" value="Tax Rate: "/>
                    <h:outputText value="7%"/>
                    
                    <h:outputLabel style="font-weight: bold" value="Status: "/>
                    <h:selectOneMenu id="status" value="#{soManagerBean.salesOrder.salesOrderStatus}">
                        <f:selectItem itemLabel="Select a Status" itemValue="" />
                        <f:selectItems value="#{soManagerBean.statuses}"/>
                    </h:selectOneMenu>
                </h:panelGrid>

                <p:panel id="panel2" header="Shipping Terms">
                    <h:panelGrid id="panelgrid2" columns="6" cellpadding="10">
                        <h:outputLabel style="font-weight: bold" value="Freight On Board: "/>
                        <h:selectBooleanCheckbox id="fob" value="#{soManagerBean.salesOrder.freightOnBoard}"/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value="Shipping Details: "/>
                        <h:selectOneRadio id="shipment" value="#{soManagerBean.salesOrder.fullShipment}">
                            <f:selectItem itemLabel="Full Shipment" itemValue="true"/>
                            <f:selectItem itemLabel="Partial Shipment" itemValue="false"/>
                        </h:selectOneRadio>
                    </h:panelGrid>
                </p:panel>
                <br/>

                <p:panel id="panel3" header="Order Items">
                    <p:dataTable id="olTable" var="deliveryOrderRow" rowIndexVar="rowIndex" value="#{soManagerBean.salesOrder.deliveryOrders}" emptyMessage="No order lines is added to Purchase Order" style="border-color: transparent">  
                        <p:column style="border-color: transparent">  
                            <p:panel id="olpanel" header="Order Line #{rowIndex + 1}" >  
                                <h:panelGrid id="olpanelgrid" columns="2" style="border-color: transparent">
                                    <h:outputLabel style="font-weight: bold" value="Lead Time: "/>
                                    <h:outputText value="#{deliveryOrderRow.leadTime}" />
                                    <h:outputLabel style="font-weight: bold" value="Shipping Address: "/>
                                    <h:outputText value="#{deliveryOrderRow.shippingAddress.addressLine1}" />
                                    <h:outputLabel style="font-weight: bold" value=""/>
                                    <h:outputText value="#{deliveryOrderRow.shippingAddress.addressLine2}" />
                                    <h:outputLabel style="font-weight: bold" value=""/>
                                    <h:outputText value="#{deliveryOrderRow.shippingAddress.city}" />
                                    <h:outputLabel style="font-weight: bold" value=""/>
                                    <h:outputText value="#{deliveryOrderRow.shippingAddress.stateName}" />
                                    <h:outputLabel style="font-weight: bold" value=""/>
                                    <h:outputText value="#{deliveryOrderRow.shippingAddress.country}" />
                                    <h:outputLabel style="font-weight: bold" value=""/>
                                    <h:outputText value="#{deliveryOrderRow.shippingAddress.zipCode}" />
                                </h:panelGrid>
                                <p:dataTable id="olilTable" var="il" value="#{deliveryOrderRow.itemLines}" emptyMessage="No products selected">  
                                    <p:column rendered="#{il.qtyOrderedCase != 0}">  
                                        <f:facet name="header">  
                                            Item Name
                                        </f:facet>  
                                        <h:outputText value="#{il.product.productType}" />  
                                    </p:column>
                                    <p:column rendered="#{il.qtyOrderedCase != 0}">  
                                        <f:facet name="header">  
                                            Unit Price
                                            <br />
                                            (per Bar)
                                        </f:facet>  
                                        <h:outputText value="#{il.unitPrice}" />  
                                    </p:column>
                                    <p:column rendered="#{il.qtyOrderedCase != 0}">  
                                        <f:facet name="header">  
                                            Quantity
                                            <br />
                                            (cases)
                                        </f:facet>  
                                        <h:outputText value="#{il.qtyOrderedCase}" />  
                                    </p:column>
                                    <p:column rendered="#{il.qtyOrderedCase != 0}">
                                        <f:facet name="header">  
                                            Order
                                            <br />
                                            Discount
                                        </f:facet>  
                                        <h:outputText value="#{il.orderDiscount}" />  
                                    </p:column>
                                    <p:column rendered="#{il.qtyOrderedCase != 0}">
                                        <f:facet name="header">  
                                            Member
                                            <br />
                                            Discount
                                        </f:facet>  
                                        <h:outputText value="#{soManagerBean.salesOrder.customer.memberDiscountGroup.memberDiscount}" />  
                                    </p:column>
                                    <p:column rendered="#{il.qtyOrderedCase != 0}">
                                        <f:facet name="header">  
                                            Subtotal
                                        </f:facet>  
                                        <h:outputText value="#{il.subTotal}" />  
                                    </p:column>
                                </p:dataTable>
                            </p:panel>                            
                        </p:column>
                    </p:dataTable>
                </p:panel>
                <br/>
                <div align="right">
                    <h3>
                        <h:panelGrid columns ="2" cellpadding="10">
                           <h:outputLabel for="subtotal" style="font-weight: bold" value="Subtotal: "/>
                            <h:outputText id="subtotal" value="#{poManagerBean.purchaseOrder.subtotal}">
                                <f:convertNumber type="currency"/>
                            </h:outputText>

                            <h:outputLabel for="tax" style="font-weight: bold" value="Tax: "/>
                            <h:outputText id="tax" value="#{poManagerBean.purchaseOrder.tax}">
                                <f:convertNumber type="currency"/>
                            </h:outputText>

                            <h:outputLabel for="total" style="font-weight: bold" value="Total: $"/>
                            <h:outputText id="total" value="#{poManagerBean.purchaseOrder.total}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                        </h:panelGrid>
                    </h3>
                </div>
            </p:panel>
            <p:commandButton id="confirmSO" value="Confirm Sales Order" ajax="false" action="#{soManagerBean.persistSalesOrder}" image="ui-icon ui-icon-disk" />
            <p:commandButton id="cancelSO" value="Don't save" ajax="false" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="cancellation"/>
        </h:form>

        <p:confirmDialog message="Are you sure about cancelling creating the sales order?" width="200"  
                         showEffect="explode" hideEffect="explode"  
                         header="Initiating cancellation" severity="alert" widgetVar="confirmation">
            <h:form id="confirmDialog">
                <p:commandButton value="Yes" update="growl" action="#{soManagerBean.cancelCreateSalesOrder}" oncomplete="confirmation.hide()"/>  
                <p:commandButton value="No" onclick="confirmation.hide()" type="button" />
            </h:form>
        </p:confirmDialog>

    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>